package com.csy.safethread;

import com.csy.util.ILogFactory;

class ThreadTest01 implements Runnable, ILogFactory {
    private int count = 100;

    public void run() {
        while (count > 0) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            sale();
        }
    }

    public synchronized void sale() {
        if (count > 0) {
            log.info("{},出售第{}张票", Thread.currentThread().getName(), 100 - count + 1);
            count--;
        }
    }
}

public class Test001 {
    public static void main(String[] args) {
        ThreadTest01 threadTest01 = new ThreadTest01();
        Thread thread1 = new Thread(threadTest01, "窗口1");
        Thread thread2 = new Thread(threadTest01, "窗口2");
        thread1.start();
        thread2.start();
    }
}
